<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=request.getContextPath()%>/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>医院管理 - 医疗预约系统后台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link rel="stylesheet" href="statics/css/hisStyle.css">
    <link rel="stylesheet" href="statics/css/common-styles.css">
</head>
<body>

<%@include file="../common/sidebar.jsp"%>
<div class="main-content">
    <%@include file="../common/top.jsp"%>
    <div class="content">
        <div class="function-page">
            <!-- 页面标题 -->
            <div class="page-header">
                <h1>医院管理</h1>
            </div>
            
            <!-- 操作按钮区 -->
            <div class="action-bar">
                <a href="hospital/toAdd" class="btn btn-primary">
                    <i class="fas fa-plus"></i>
                    新增医院
                </a>
            </div>

            <!-- 查询表单 -->
            <div class="search-filter">
                <form id="hospitalFindForm" action="hospital/find" method="get">
                    <div class="form-group">
                        <label for="hospitalname">医院名称：</label>
                        <input type="text" id="hospitalname" name="hospitalname" value="${condition.hospitalName}" placeholder="请输入医院名称" class="form-control"/>
                    </div>
                    <button type="submit" class="btn btn-primary">查询</button>
                </form>
                <div class="search-info">总计${pageInfo.total}家医院</div>
            </div>
            <!-- 数据表格区域 -->
            <div class="data-section">
                <table class="data-table">
                    <thead>
                    <tr>
                        <th>医院ID</th>
                        <th>医院名称</th>
                        <th>地址</th>
                        <th>联系电话</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${pageInfo.list}" var="hospital">
                        <tr>
                        <td>${hospital.hospitalId}</td>
                        <td>${hospital.hospitalName}</td>
                        <td>${hospital.address}</td>
                        <td>${hospital.hphone}</td>
                            <td class="operations">
                                <a href="hospital/toEdit?hospitalId=${hospital.hospitalId}" class="btn btn-secondary btn-sm">
                                    <i class="fas fa-edit"></i> 编辑
                                </a>
                                <a href="hospital/removeById?hospitalId=${hospital.hospitalId}" class="btn btn-danger btn-sm delete-btn"
                                   onclick="return confirm('确定删除该医院吗？删除前请确保该医院下没有科室！')">
                                    <i class="fas fa-trash-alt"></i> 删除
                                </a>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
            
            <!-- 分页控件 -->
            <div class="pagination-container">
                <div class="pagination">
                    <c:if test="${pageInfo.pageNum > 1}">
                        <a href="hospital/find?pageNum=1&hospitalname=${condition.hospitalName}" class="pagination-link">
                            <i class="fas fa-angle-double-left"></i> 首页
                        </a>
                        <a href="hospital/find?pageNum=${pageInfo.pageNum-1}&hospitalname=${condition.hospitalName}" class="pagination-link">
                            <i class="fas fa-angle-left"></i> 上一页
                        </a>
                    </c:if>
                    
                    <c:forEach items="${pageInfo.navigatepageNums}" var="pageNum">
                        <c:if test="${pageNum == pageInfo.pageNum}">
                            <a href="hospital/find?pageNum=${pageNum}&hospitalname=${condition.hospitalName}" class="pagination-link active">${pageNum}</a>
                        </c:if>
                        <c:if test="${pageNum != pageInfo.pageNum}">
                            <a href="hospital/find?pageNum=${pageNum}&hospitalname=${condition.hospitalName}" class="pagination-link">${pageNum}</a>
                        </c:if>
                    </c:forEach>
                    
                    <c:if test="${pageInfo.pageNum < pageInfo.pages}">
                        <a href="hospital/find?pageNum=${pageInfo.pageNum+1}&hospitalname=${condition.hospitalName}" class="pagination-link">
                            <i class="fas fa-angle-right"></i> 下一页
                        </a>
                        <a href="hospital/find?pageNum=${pageInfo.pages}&hospitalname=${condition.hospitalName}" class="pagination-link">
                            <i class="fas fa-angle-double-right"></i> 末页
                        </a>
                    </c:if>
                </div>
            </div>
            <span class="pagination-info">共 ${pageInfo.total} 条记录，当前第 ${pageInfo.pageNum} / ${pageInfo.pages} 页</span>
        </div>
    </div>
</div>
<script type="text/javascript">
    // 为侧边栏的医院管理项添加激活状态
    document.addEventListener('DOMContentLoaded', function() {
        const menuItems = document.querySelectorAll('.menu-item');
        menuItems.forEach(item => {
            if (item.getAttribute('href') === 'hospital/find' || item.getAttribute('href') === '${pageContext.request.contextPath}/hospital/find') {
                item.classList.add('active');
            } else {
                item.classList.remove('active');
            }
        });
    });

    function removeById(hospitalid) {
        if (confirm("确定删除该医院吗？删除前请确保该医院下没有科室！")) {
            window.location.href = "hospital/removeById?hospitalId=" + hospitalid;
        }
    }
</script>
</body>
</html>